package client;

import com.mysql.jdbc.Messages;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class Send implements Runnable {
    //要发送的消息
    private Object obj;
    //对象流
    private ObjectOutputStream oos;
    //控制线程标识
    private boolean isRunning = true;

    public Send(Socket socket) throws IOException {
       this.oos=new ObjectOutputStream(socket.getOutputStream());
    }

    public void send(Object obj){
        try{
            if(obj!=null){
                oos.writeObject(obj);
                oos.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
            isRunning=false;
        }
    }
    @Override
    public void run() {
      while(isRunning){
          send(obj);
          obj=null;
      }
    }
}
